{% extends base.html %}

{% block body_left %}

<div class="col-md-12 grid-card">
    <h3 class="card-title btn-line-height">
        <span>定时任务</span>
        <div class="float-right">
            <!-- 不推荐脚本+配置来创建定时任务，直接通过插件来设置
            <input class="dialog-btn" type="button" value="新增任务" dialog-url="/system/crontab/edit" />
            -->
            {% include common/button/back_button.html %}
        </div>
    </h3>
</div>

<div class="card">
    <table class="table col-md-12">
        <tr>
            <th>编号</th>
            <th>任务</th>
            <th>时间</th>
            <th>操作</th>
        </tr>
        {% set index = -1 %}
        {% for index, task in enumerate(task_list) %}
        {% set name = task.url %}
        <tr class="">
            <td class="row-no">{{index+1}}</td>
            <td>
                <div style="word-wrap: break-word;">
                    {% if task.protocol == "script" %}
                        <a href="{{_server_home}}/code/edit?path={{task.script_name}}&type=script">{{task.script_name}}</a>
                    {% else %}
                        {{task.display_name}}
                    {% end %}
                </div>
            </td>
            <td>{{ display_time_rule(task) }}</td>
            <td style="width:110px;">
                {% if task.id %}
                    <input class="dialog-btn" type="button" value="编辑" 
                        dialog-url="/system/crontab/edit?id={{task.id}}"
                        dialog-title="编辑任务"
                        href="{{_server_home}}/system/crontab/edit?id={{task.id}}" />
                    <input type="button" class="link-btn btn-danger" value="删除" 
                        href="{{_server_home}}/system/crontab/remove?id={{task.id}}" 
                        confirm-message="确认删除 {{task.display_name}} ?">
                {% end %}
            </td>
        </tr>
        {% end %}
    </table>
</div>


<script type="text/javascript">
    $("#url_type").on("change", function (event) {
        console.log(event);
        var target = event.target;
        var value = $(target).val();
        if (value == "script") {
            $("select[name=script_url]").show();
            $("input[name=url]").val("").hide();
        } else {
            $("input[name=url]").show();
            $("select[name=script_url]").val("").hide();
        }
    })
</script>
{% end %}

{% block body_right %}
    {% include system/component/admin_nav.html %}
{% end %}